package com.web.login.action;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.web.login.model.User;
import com.web.login.service.CRUDService;
import com.web.login.service.CRUDServiceImpl;

public class UserAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static Long id = (long) -1;
	private static User user;
	private List<User> listUser = new ArrayList<User>();

	private CRUDService service = new CRUDServiceImpl();

	public String insertOrUpdateUser() {
		service.createOrEditUser(id, user);
		id = (long) -1;
		return SUCCESS;
	}

	public String selectUser() {
		service.readUser(listUser);
		return SUCCESS;
	}

	public String updateUser() {
		user = service.editUser(id);
		return SUCCESS;
	}

	public String deleteUser() {
		service.deleteUser(id);
		id = (long) -1;
		return SUCCESS;
	}

	public String deleteAll() {
		service.deleteAllUsers();
		return SUCCESS;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public List<User> getListUser() {
		return listUser;
	}

	public void setListUser(List<User> listUser) {
		this.listUser = listUser;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

}
